<style type="text/css" title="currentStyle">
	@import "../media/css/demo_page.css";
	@import "../media/css/demo_table_jui.css";
	@import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
	@import "media/css/TableTools_JUI.css";
</style>
<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		$('#example').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": 'Tlfrtip',
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
	} );
</script>
<?php
function GetRemoteLastModified( $uri )
{
    // default
    $unixtime = 0;
   
    $fp = @fopen( $uri, "r" );
    if( !$fp ) {return;}
   
    $MetaData = stream_get_meta_data( $fp );
       
    foreach( $MetaData['wrapper_data'] as $response )
    {
        // case: redirection
        if( substr( strtolower($response), 0, 10 ) == 'location: ' )
        {
            $newUri = substr( $response, 10 );
            fclose( $fp );
            return GetRemoteLastModified( $newUri );
        }
        // case: last-modified
        elseif( substr( strtolower($response), 0, 15 ) == 'last-modified: ' )
        {
            $unixtime = date('d-m-Y h:i:s A',strtotime( substr($response, 15) ));
            break;
        }
    }
    fclose( $fp );
    return $unixtime;
}
function chk_folder($filename)
{
	$fp_load = @fopen("$filename", "rb");
	if ( $fp_load )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function get_text($filename)
{
	$fp_load = @fopen("$filename", "rb");
	if ( $fp_load )
	{
		while ( !feof($fp_load) )
		{
			$content .= fgets($fp_load, 102400);
		}
		fclose($fp_load);
		return $content;
	}
}

$selUsers="SELECT * FROM tb_clientinfo";				
$q = $selUsers;
$r = mysql_query($q);

$selUsers=$selUsers." ORDER BY ci_clientName ";
$rs_getUserDetails = mysql_query($selUsers);

?>
<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="example">      
  <thead>
<tr>
	<th width="2%">#</th>
    <th>IMEI&nbsp;/&nbsp;Track ID</th>
    <th width="20%">Last data received Date & Time</th>
    <th width="20%" style="border:0px;">File Modified Date & Time</th>
</tr>
</thead>
<tbody>
<?php

$path1 = DATAPATH.date('d-m-Y')."/";
$chkFolder=chk_folder($path1);
$count = 1;

if($chkFolder)
{
	preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", get_text($path1), $matches);  
	//print_r($matches[2]);
	for($i=1;$i<count($matches[2]);$i++)
	{
		$tmpVehi = explode('.',$matches[2][$i]);
?>
  
   <?php 
		
		$getLiveData = "SELECT * FROM tb_livegps_info WHERE tli_imei = '".$tmpVehi[0]."'";
		$exeLiveData = $db->query($getLiveData);
		if($db->affected_rows == 0)
		{
			echo "<tr><td>".$count."</td>";
			echo "<td>".$tmpVehi[0]."</td>";
			$date1 = date('d-m-Y',mktime(0,0,0,date("m"),(date("d")-$m),date("Y")));
			$path = $path1."/".$tmpVehi[0].".txt";
			
			$fp_load = @fopen($path , "rb");
			if ($fp_load) 
			{ 
				while(!@feof($fp_load)) 
				{
					$data111 = @fgets($fp_load);
				} 
				$data111 = getSortedData($data111);
				$data111_arr1 = explode('#',$data111);
				$data111_arr1 = explode(',',$data111_arr1[count($data111_arr1)-2]);
				$gpsTime = $data111_arr1[8]." ".$data111_arr1[9];
				echo "<td>".$gpsTime."</td>";
				echo "<td>".GetRemoteLastModified($path)."</td></tr>";
			} 	
			$count++;
		}
	?>
  </tr>
  <?php 
}		
}
?>    
</tbody>
</table>

<form name="formpagination" id="formpagination" action="" method="post">
	<input type="hidden" name="pn" id="pn" value="<?php if(isset($_POST[pn])) echo $_POST[pn]; else echo '1'; ?>" />
	<input type="hidden" name="nr" id="nr" value="<?php echo $_POST[nr]?>" />
	<input type="hidden" name="search_vehicle_no" id="search_vehicle_no" value="<?php echo $_POST[search_vehicle_no]; ?>">
	<input type="hidden" name="client_id" id="client_id" value="<?php echo $_POST[client_id]; ?>">
	<input type="hidden" name="pageSelect" value="" />
</form>